import { Chip } from '@mui/material';

import Disbursement from '../api/disbursement/disbursement';

interface Props {
    disbursement: Disbursement;
}

const DisbursementStatus = (props: Props) => {
    const { disbursement } = props;

    const getName = (): string => {
        if (disbursement.doneDisbursing == true) {
            if (disbursement.sent == disbursement.total) {
                return 'Successful';
            } else {
                return 'Failed';
            }
        } else {
            return 'Pending';
        }
    };

    const getColor = () => {
        switch (getName()) {
            case 'Failed':
                return 'error';
            case 'Successful':
                return 'success';
        }

        return 'default';
    };

    return (
        <>
            <Chip label={getName()} color={getColor()} />
            {getName() == 'Failed' && (
                <>
                    <br />
                    <div className="top-10">
                        <small>
                            {disbursement.failed}{' '}
                            {disbursement.failed == 1 ? ' transaction' : ' transactions'}
                        </small>
                    </div>
                </>
            )}
        </>
    );
};

export default DisbursementStatus;
